#include <iostream>
using std::cout;
using std::endl;

//值传递
//用实参初始化形参，实际是复制的效果
//函数体中操作的是实参的副本
void swap(int x,int y){
    int temp = x;
    x = y;
    y = temp;
}

//地址传递
void swap2(int * px,int * py){
    int temp = *px;
    *px = *py;
    *py = temp;
}

//引用传递，形参初始化时不会发生复制
//int & x = a;
//int & y = b;
//在函数体中对引用进行操作，会影响到其绑定的本体
void swap3(int & x,int & y){
    int temp = x;
    x = y;
    y = temp;
}

void func(const int & x){
    /* x = 100; */
    cout << x << endl;
}

void test0(){
    int a = 10, b = 20;
    /* swap(a,b); */
    /* swap2(&a,&b); */
    swap3(a,b);
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;
}

int main(void){
    test0();
    return 0;
}
